/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.recption.service;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.recption.dao.RecptionReportDao;
import com.thinkgem.jeesite.modules.recption.entity.RecptionReport;
import com.thinkgem.jeesite.modules.shelvesreport.dao.ShelvesReportDao;
import com.thinkgem.jeesite.modules.shelvesreport.entity.ShelvesReport;

/**
 * 收货报告Service
 * @author zxl
 * @version 2017-08-04
 */
@Service
@Transactional(readOnly = true)
public class RecptionReportService extends CrudService<RecptionReportDao, RecptionReport> {
	@Autowired
	private ShelvesReportDao shelvesReportDao;

	public RecptionReport get(String id) {
		return super.get(id);
	}
	
	public List<RecptionReport> findList(RecptionReport recptionReport) {
		return super.findList(recptionReport);
	}
	
	public Page<RecptionReport> findPage(Page<RecptionReport> page, RecptionReport recptionReport) {
		recptionReport.getSqlMap().put("dsf", dataScopeFilter(recptionReport.getCurrentUser(), "o2", null));
		recptionReport.setPage(page);
		return super.findPage(page, recptionReport);
	}
	
	@Transactional(readOnly = false)
	public void save(RecptionReport recptionReport) {
		if(StringUtils.isEmpty(recptionReport.getId())){
			ShelvesReport shelvesReport = new ShelvesReport();
			shelvesReport.setWinitOrderNo(recptionReport.getWinitOrderNo());
			shelvesReport.setPackageQty("0");
			shelvesReport.setActuPackageQty(recptionReport.getActuPackageQty());
			shelvesReport.setOffice(recptionReport.getOffice());
			shelvesReport.setActuEntryWarhousenameTime(new Date());
			shelvesReport.setActuProductQty("0");
			shelvesReport.setProductQty("0");
			shelvesReport.setItemQty("0");
			shelvesReport.setActuItemQty("0");
			shelvesReport.setWinitProductName("无订单仓库到货");
			shelvesReport.preInsert();

			shelvesReportDao.insert(shelvesReport);
		}
		super.save(recptionReport);
	}
	
	@Transactional(readOnly = false)
	public void delete(RecptionReport recptionReport) {
		super.delete(recptionReport);
	}
	
}